﻿using System;
using System.Linq;

class MostFrequentNumber
{
    static void Main()
    {
        Console.Write("Number of elements of array:");
        int arrayLength = int.Parse(Console.ReadLine());
        int[] array = new int[arrayLength];
        for (int i = 0; i < arrayLength; i++)
        {
            Console.Write("\nInt element a[{0}]:", i);
            array[i] = int.Parse(Console.ReadLine());
        }
        //int[] array = new int[] { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 ,9,9,9,9,9};

        Array.Sort(array);

        int number = 0;
        int occurences = 1;

        int candidateNumberOccurences = 1;

        for (int i = 0; i < array.Length-1; i++)
        {
            if (array[i] == array[i + 1])
            {
                candidateNumberOccurences++;
                if (candidateNumberOccurences > occurences)
                {
                    occurences = candidateNumberOccurences;
                    number = array[i];
                }
            }
            else
            {
                candidateNumberOccurences = 1;
            }
        }
        Console.WriteLine("The number {0} is found {1} times", number, occurences);
    }
}